from microbit import *

pwm = 0

while True:
    if button_a.was_pressed():
        if pwm < 1008:
            pwm += 16
            pin0.write_analog(pwm)

    if button_b.was_pressed():
        if pwm >= 16:
            pwm -= 16
            pin0.write_analog(pwm)

